#!/usr/bin/ruby -Ku
# -*- coding: utf-8 -*-
require 'test/unit'
require 'm3g'

class Test_Transformable < Test::Unit::TestCase
  def setup
  end

  def teadown
  end

  def test_defualt_variables
    tra = M3G::Group.new
    trns = tra.transform

    # T,R,S,M
    assert_equal [0,0,0]   , tra.translation  
    assert_equal [0, 0,0,0], tra.orientation
    assert_equal [1,1,1]   , tra.scaling
    assert_equal [1,0,0,0,
                  0,1,0,0,
                  0,0,1,0,
                  0,0,0,1], trns.matrix
    
  end

  def test_set_variables
    tra = M3G::Group.new
    trns = M3G::Transform.new
    trns.matrix = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]

    # set T,R,S,M
    tra.translation  = [1,2,3]
    tra.orientation  = [90, 1,0,0]
    tra.scaling      = [1,2,3]
    tra.transform    = trns

    assert_equal [1,2,3]    , tra.translation  
    assert_in_delta 90.0, tra.orientation[0], 0.00001
    assert_in_delta 1,    tra.orientation[1], 0.00001
    assert_in_delta 0,    tra.orientation[2], 0.00001
    assert_in_delta 0,    tra.orientation[3], 0.00001
    assert_equal [1,2,3]    , tra.scaling
    assert_equal [1,2,3,4,
                  5,6,7,8,
                  9,10,11,12,
                  13,14,15,16], trns.matrix
  end

  def test_add_variables
    tra = M3G::Group.new
    trns = M3G::Transform.new
    trns.matrix = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]


    # set T,R,S,M
    tra.translation  = [1,1,1]
    tra.orientation  = [90, 0,0,1]
    tra.scaling      = [2,2,2]
    tra.transform    = trns

    # puts "ori = #{tra.orientation.join(', ')}"

    # add T,R,S
    tra.translate   1,2,3
    tra.post_rotate 90, 0,1,0
    tra.pre_rotate  90, 1,0,0
    tra.scale       1,2,3

    assert_equal [2,3,4]    , tra.translation  
    assert_in_delta 90      , tra.orientation[0], 0.00001
    assert_in_delta 0       , tra.orientation[1], 0.00001
    assert_in_delta 0       , tra.orientation[2], 0.00001
    assert_in_delta 1       , tra.orientation[3], 0.00001
    assert_equal [2,4,6]    , tra.scaling
    assert_equal [1,2,3,4   ,
                  5,6,7,8   ,
                  9,10,11,12,
                  13,14,15,16], tra.transform.matrix

  end

  def test_duplicateA
    tra = M3G::Group.new
    trns = M3G::Transform.new
    trns.matrix = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]

    # set T,R,S,M
    tra.translation  = [1,2,3]
    tra.orientation  = [90, 1,0,0]
    tra.scaling      = [1,2,3]
    tra.transform    = trns

    tra2 = tra.duplicate

    assert_equal [1,2,3]    , tra2.translation  
    assert_in_delta 90.0, tra2.orientation[0], 0.00001
    assert_in_delta 1,    tra2.orientation[1], 0.00001
    assert_in_delta 0,    tra2.orientation[2], 0.00001
    assert_in_delta 0,    tra2.orientation[3], 0.00001
    assert_equal [1,2,3]    , tra2.scaling
    assert_equal [1,2,3,4,
                  5,6,7,8,
                  9,10,11,12,
                  13,14,15,16], tra2.transform.matrix


  end
end
